package org.lg.service.impl;

import org.lg.entity.User;
import org.lg.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    // 用户注册
    public String registerUser(User user) {
        User existingUser = userMapper.getUserByUsername(user.getUsername());
        if (existingUser != null) {
            return "用户已存在!";
        }
        userMapper.createUser(user);
        return "用户注册成功!";
    }

    // 用户登录
    public String loginUser(String username, String password) {
        User user = userMapper.getUserByUsername(username);
        if (user != null && user.getPassword().equals(password)) {
            return "用户登录成功!";
        }
        return "用户名或密码无效，请重试!";
    }
}
